'use strict'

var http = require('http');
var fs = require('fs');
const { LOADIPHLPAPI } = require('dns');

var documentRoot = 'C:\Program Files\nodejs\node.exe c:\Users\Administrator\Desktop\grade19_soft1_course_note2\李兆龙';

var server= http.createServer((req,res)=>{

    var url = documentRoot; 
    var file = documentRoot + url
    console.log(file);
    fs.readFile(file,(err,data)=>{
        if(err){
            res.writeHeader(404,{
                'content-type' : 'text/html;charset="utf-8"'
            });
            res.write('<h1>404</h1><p>页面不存在</p>');
            res.end();
        }else{
            res.writeHeader(200,{
                'content-type' : 'text/html;charset="utf-8"'
            });
            res.write(data);
            res.end();
        }
    })
})

let port = 7979;

server.listen(port);

console.log(`Server running at Http://127.0.0.1:${port}`);